package com.maxtech.common;

import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnRouteParams;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.location.Location;
import android.net.Uri;
import android.os.Message;
import android.util.Log;

import com.maxtech.basestation.LocationUtil0;
import com.maxtech.common.gps.IAddressTask;

public class AddressTask extends IAddressTask {
	protected static final String TAG = "AddressTask";

	public static final int DO_APN = 0;
	public static final int DO_WIFI = 1;
	public static final int DO_GPS = 2;
	private int postType = -1;
	private Context context;
	public AddressTask(Activity context, int postType) {
		super(context);
		this.context = context;
		this.postType = postType;
	}
	
	@Override
	public HttpResponse execute(JSONObject params) throws Exception {
		HttpClient httpClient = new DefaultHttpClient();

		HttpConnectionParams.setConnectionTimeout(httpClient.getParams(),
				20 * 1000);
		HttpConnectionParams.setSoTimeout(httpClient.getParams(), 20 * 1000);

		HttpPost post = new HttpPost("http://www.google.com/loc/json");
		// 设置代理
		if (postType == DO_APN) {
			LocationUtil0 locationutil = new LocationUtil0(context);		
//			locationutil.setOnGetLocationListener(new LocationUtil.GetLocationListener(){
//				@Override
//				public void OnGetLocationListener(Location location) {
//					if(location==null) {
//
//						return;
//					}
//
//					Log.e(TAG, "location.getLatitude():" + location.getLatitude() 
//							+ "location.getLongitude():" + location.getLongitude());
//				}
//
//				@Override
//				public void OnGetCityNameListener(String cityname) {
//					if(cityname!=null) {
//						Log.e(TAG, "cityname:" + cityname);
//
//					}
//				}
//			});
			
			locationutil.getLocationByMobile();
		}
		
		StringEntity se = new StringEntity(params.toString());
		post.setEntity(se);
		HttpResponse response = httpClient.execute(post);
		return response;
	}
}
